import 'package:bxultimate/data/request/organization_request.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'state.dart';

class OrganizationAttendanceDetailController extends GetxController
    with GetSingleTickerProviderStateMixin {
  final OrganizationAttendanceDetailState state =
      OrganizationAttendanceDetailState();
  TabController? tabController;

  var tabItem = ['已签到', '未签到'];

var id = Get.arguments;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    tabController = TabController(length: tabItem.length, vsync: this);
    getData();
  }

  void getData() async {
    // 获取考勤详情
    state.attendanceItem =
        await OrganizationRequest.getAttendanceClockingDetail(Get.arguments);

    getAnalysis();
  }

  void getAnalysis() async{
    state.alreadyUserList = await OrganizationRequest.getClockingRecordsList(
        id, 'already', state.currentDate);
    state.noSignedUserList = await OrganizationRequest.getClockingRecordsList(
        id, 'not',state.currentDate);
  }

  void showTimeSelect() {
    var now = DateTime.now();
    TDPicker.showDatePicker(Get.context, title: '选择时间', onConfirm: (selected) {
      state.currentDate =
      '${selected['year'].toString()}-'
          '${selected['month'].toString().padLeft(2, '0')}-'
          '${selected['day'].toString().padLeft(2, '0')}';
      getAnalysis();
      Get.back();
    },
      initialDate: [
        now.year,
        now.month,
        now.day,
      ]);
  }
}
